package com.huijie.core.util.exportexcel;

import org.springframework.web.servlet.ModelAndView;

import java.text.DecimalFormat;
import java.util.HashMap;
import java.util.Map;


/**
* @ClassName: CommonHelper 
* @Description: 公共帮助类
* @author JsonY 
* @date 2017年11月13日 下午2:45:44 
*/
public class CommonHelper{
	
	
	/**
	 * 获得excel model and view
	 * 
	 * @param excelExportBean
	 * @return excel model and view
	 */
	public static ModelAndView getExcelModelAndView(Object excelExportBean){
		return getExcelModelAndView(excelExportBean, null);
	}
	
	/**
	 * 获得excel model and view
	 * 
	 * @param excelExportBean
	 * @return excel model and view
	 */
	public static ModelAndView getExcelModelAndView(Object excelExportBean, String excelName){
		Map<String, Object> map = new HashMap<String, Object>();
		map.put(ExcelView.EXCEL_EXPORT_BEAN, excelExportBean);
		map.put(ExcelView.EXCEL_EXPORT_NAME, excelName);
		if(excelExportBean instanceof ExcelExport){
			map.put(ExcelView.EXCEL_EXPORT_TYPE, ExcelView.EXCEL_EXPORT_TYPE_SINGLE_SHEET);
		}else{
			map.put(ExcelView.EXCEL_EXPORT_TYPE, ExcelView.EXCEL_EXPORT_TYPE_MULTIPLE_SHEET);
		}
		return new ModelAndView(new ExcelView(), map);
	}
	
	public static String thousandsSeparatorFormat(Long longValue) {
		DecimalFormat df = new DecimalFormat("#,###");
		return df.format(longValue);
	}

}
